﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;

namespace Web.Views.ArchiveManage
{
    public partial class ArchiveMenuMange : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }

        protected void BindGrid()
        {
            DataTable dt = GetArchiveRoles();
            this.gv_MenuManage.DataSource = PageDataList.GetPagedTable(dt, pager.CurrentPageIndex, pager.PageSize);
            pager.RecordCount = dt.Rows.Count;
            this.gv_MenuManage.DataBind();
        }


        private DataTable GetArchiveRoles()
        {
            try
            {
                //查看拥有档案录入、审核、上交，接收的菜单的权限的角色
                //有档案数据管理的角色也包含进来，20140721
                string Sql = @"select distinct a.ROLE_ID,a.ROLE_NAME,a.REMARK from P_auth_role a
join p_Auth_Role_Function c on a.role_id=c.role_id
join p_Auth_Function d on c.func_id = d.func_id
join p_Auth_Menu e on d.menu_id = e.menu_id
where e.menu_id in ('ePlanet.ArchiveManage.ArchiveFile','ePlanet.ArchiveManage.ArchiveRecord','ePlanet.ArchiveManage.ArchiveReceive','ePlanet.ArchiveManage.ArchiveHandin','ePlanet.ArchiveManage.ArchiveDeptDone','ePlanet.ArchiveManage.ArchiveFileArchiveManageFrame') 
order by a.ROLE_NAME";
                IMDataHelper dal = new IMDataHelper();
                DataTable dt = dal.DBHelper.ExecuteDataSet(Sql).Tables[0];
                return dt;
            }
            catch(Exception ex)
            {
                return null;
            }
        }

        //翻页事件
        protected void pager_PageChanging(object sender, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            pager.CurrentPageIndex = e.NewPageIndex;
            BindGrid();
        }

        /// <summary>
        /// 编辑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gv_MenuManage_RowEditing(object sender, GridViewEditEventArgs e)
        {
            string pkValue = this.gv_MenuManage.DataKeys[e.NewEditIndex].Value.ToString();
            this.Response.Redirect("ArchiveMenuManageEdit.aspx?role_id=" + pkValue + "");
        }
    }
}